import babel from 'rollup-plugin-babel';
import {uglify} from 'rollup-plugin-uglify';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import path from 'path';
import { obfuscator } from 'rollup-obfuscator';
import myExample from './myplugin';
import nodeResolve from 'rollup-plugin-node-resolve';
import webworkify from 'rollup-plugin-webworkify-fjo';
const externalId = path.resolve(__dirname , 'src/lib/three.module.js')
export default {
  input: 'src/index.js', // 入口文件
  external:[externalId],
  output: {
    // format: 'iife',
    format: 'umd',
    // format: 'amd',
    // dir:'dist',
    file: 'dist/testmap.js', // 打包后输出文件
    name: 'testMap',  // 打包后的内容会挂载到window，name就是挂载到window的名称
    sourcemap: false, // 代码调试  开发环境填true
    globals:{
      [externalId]: 'THREE',
    }
  },
  plugins: [
    babel({
      exclude: "node_modules/**",
      runtimeHelpers: true,
      // externalHelpers: true
    }),
    nodeResolve(),
    webworkify({
      // specifically patten files
      pattern: '**/*.worker.js'  // Default: undefined (follow micromath globs)
    }),
    obfuscator({
      sourceMap:false,
      compact: true,
      controlFlowFlattening: false,
      deadCodeInjection: false,
      debugProtection: false,
      debugProtectionInterval: false,
      disableConsoleOutput: false,
      identifierNamesGenerator: 'hexadecimal',
      log: false,
      numbersToExpressions: false,
      renameGlobals: false,
      selfDefending: true,
      simplify: true,
      splitStrings: false,
      stringArray: true,
      stringArrayEncoding: [],
      stringArrayIndexShift: true,
      stringArrayRotate: true,
      stringArrayShuffle: true,
      stringArrayWrappersCount: 1,
      stringArrayWrappersChainedCalls: true,
      stringArrayWrappersParametersMaxCount: 2,
      stringArrayWrappersType: 'variable',
      stringArrayThreshold: 0.75,
      unicodeEscapeSequence: false,
    }),
    // 压缩代码
    uglify(),
    myExample(),
    // 热更新 默认监听根文件夹
    livereload(),
    // 本地服务器
    serve({
      open: true, // 自动打开页面
      port: 8000, 
      openPage: '/public/index.html', // 打开的页面
      contentBase: ''
    })
  ]
}
// // export default {
// //     input: 'src/index.js',
// //     output: {
// //       file: 'main.js',
// //       format: 'iife',
// //       globals:{
// //         'src/moduleA.js':'esmap'
// //       }
// //     },
 
// //   };